package cn.bb.action;

import cn.bb.pojo.Article;
import cn.bb.pojo.Page;
import cn.bb.service.IArticleService;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.Map;

public class ArticleAction extends ActionSupport implements ModelDriven<Object> {
    private Article article;
    @Autowired
    private IArticleService articleService;
    private Integer currentPage;//当前页
    private Integer pageSize;//每页的条数
    private Page page;
    public String selArticle(){
        Map<String,Object> map = new HashMap();
        map.put("currentPage",currentPage);
        map.put("pageSize",pageSize);
        page = articleService.getAllArticle(map);
        System.out.println(page);
        return SUCCESS;
    }
    public String addArticle(){
        System.out.println(article);
        int i = articleService.insertArticle(article);
        System.out.println(i);
        return SUCCESS;
    }
    public Article getArticle() {
        return article;
    }

    public void setArticle(Article article) {
        this.article = article;
    }

    public IArticleService getArticleService() {
        return articleService;
    }

    public void setArticleService(IArticleService articleService) {
        this.articleService = articleService;
    }

    @Override
    public Article getModel() {
        if(article == null){
            article = new Article();
        }
        return article;
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Page getPage() {
        return page;
    }

    public void setPage(Page page) {
        this.page = page;
    }
}
